import socket, ssl, subprocess
from http.client import IncompleteRead
from urllib import request
import gui, vision, winGDI, winUser
from visionEnhancementProviders.screenCurtain import ScreenCurtainProvider
ssl._create_default_https_context = ssl._create_unverified_context
# 设置联网超时为60秒
socket.setdefaulttimeout(60)
#判断是否黑屏
def hasScreenCurtain():
    screenCurtainId = ScreenCurtainProvider.getSettings().getId()
    screenCurtainProviderInfo = vision.handler.getProviderInfo(screenCurtainId)
    return bool(vision.handler.getProviderInstance(screenCurtainProviderInfo))
# http post
def post(url, data=None, headers=None):
    aRequest = request.Request(url=url, headers=headers) if headers else request.Request(url=url)
    try:
        if data:
            with request.urlopen(aRequest, data) as f:
                res = f.read()
        else:
            with request.urlopen(aRequest) as f:
                res = f.read()
    except IncompleteRead as e:
        res = e.partial
    except socket.timeout as e:
        raise e
    if not res:
        raise Exception('No result.')
    return res
# 执行命令行（隐藏窗口）
def system(cmd):
    return subprocess.call(cmd, creationflags = 0x08000000)
